Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[accname] Require specification of subtest count #42769

Closed

Conversation

jugglinmike
Copy link
Contributor

@jugglinmike jugglinmike commented Oct 26, 2023

Closes web-platform-tests/interop-accessibility#105

The accname tests use a declarative style to express tests. This style is susceptible to false positives for author errors (e.g. invalid markup or typos in CSS selectors or class names).

Extend the verifyLabelsBySelector utility function with a parameter for the expected number of tests in order to reduce the risk of false positives.


Inspired by this test author error.

The accname tests use a declarative style to express tests. This style
is susceptible to false positives for author errors (e.g. invalid markup
or typos in CSS selectors or class names).

Extend the `verifyLabelsBySelector` utility function with a parameter
for the expected number of tests in order to reduce the risk of false
positives.
Comment on lines +130 to +133
verifyLabelsBySelector: function(expectedCount, selector) {
const els = document.querySelectorAll(selector);
if (!els.length) {
throw `Selector passed in verifyLabelsBySelector("${selector}") should match at least one element.`;
if (els.length !== expectedCount) {
throw `verifyLabelsBySelector expected ${expectedCount} elements but received ${els.length}`;
Copy link
Contributor

@cookiecrook cookiecrook Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for filing this! I agree it's a good move to be more explicit about the expectations.

However, this is going to break a few outstanding PRs that expect selector to be first... I also would prefer selector remain the first argument (as the method name implies) and throw a warning if a count is not provided. And the error only if it is provided but doesn't match.

comp_label.html, comp_labelledby.html, and comp_text_node.html could then be left out of this PR to avoid conflicts/breakage with the outstanding PRs. They would throw a warning but not an error, and if this lands first, we could then update the other files in those PRs (or later ones) to use the optional-but-recommended expectedCount.

@@ -32,7 +32,7 @@ <h2 class="ex" data-expectedlabel="heading label" data-testname="heading with te
<!-- Todo: test all remaining cases of https://w3c.github.io/accname/#comp_text_node -->

<script>
AriaUtils.verifyLabelsBySelector(".ex");
AriaUtils.verifyLabelsBySelector(1, ".ex");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below... Keep comp_text_node.html as-is (but with a warning) to make way for #42407

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#42407 was since merged so it's no longer necessary to leave this change out of the PR, but it should get the mentioned argument order change, and will need an update to the expectedCount integer.

@@ -31,7 +31,7 @@ <h2 id="h">div group label</h2>
-->

<script>
AriaUtils.verifyLabelsBySelector(".ex");
AriaUtils.verifyLabelsBySelector(1, ".ex");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below... Keep comp_labelledby.html as-is (but with a warning) to make way for #42522

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#42522 was since merged so it's no longer necessary to leave this change out of the PR, but it should get the mentioned argument order change, and will need an update to the expectedCount integer.

@@ -18,7 +18,7 @@
<!-- Todo: test all remaining cases of https://w3c.github.io/accname/#comp_label -->

<script>
AriaUtils.verifyLabelsBySelector(".ex");
AriaUtils.verifyLabelsBySelector(1, ".ex");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below... Keep comp_label.html as-is (but with a warning) to make way for #41463

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jugglinmike #41463 was also merged since the the time this was filed.

@cookiecrook
Copy link
Contributor

@jugglinmike Are you still working on this? Thanks.

@jugglinmike
Copy link
Contributor Author

@cookiecrook Sure! Can you say a bit more about why you'd prefer the "expected" count to be optional? (My motivation is to prevent this avenue for author error, and I can't think of any benefits to allowing folks to risk the kind of false positives that are possible today.)

@cookiecrook
Copy link
Contributor

I would expect most instances to use it, but making it optional (with a SHOULD warning) will allow an easier transition into using the new parameter. Making it optional allows you to check in the change without worrying about conflicts with the other open PRs (exception being #43740 due to its new parameter in the same function)... We can add follow-on PRs to any existing tests that are currently in flux.

@cookiecrook
Copy link
Contributor

As an example, pretty much all of my comments above are about incoming PRs (some merged now) that would conflict with the PR as written. If you changed these two things, I believe it would smooth the transition:

  • make any new parameters trailing, rather than replacing the leading parameter
  • make any new trailing parameters optional... but do fire a warning if its missing, because we do want full adoption eventually

@rahimabdi
Copy link
Contributor

rahimabdi commented Feb 3, 2024

FYI that the display: contents PR has recently landed and also adds an argument for both verifyRolesBySelector() and verifyLabelsBySelector().

As part of this issue's work, we'll need to take into account the new implementations in aria-utils.js for these verify...() functions.

I'm also working on creating common keyboard utilities with their own verify...() functions so having an aligned approach, and this PR merged beforehand preferably, would be great 🙂.

@cookiecrook
Copy link
Contributor

Assigning to Rahim to help finish this stale PR.

@cookiecrook
Copy link
Contributor

FYI @janewman

@cookiecrook
Copy link
Contributor

Thinking about this some more... This change would increase the likelihood of PR conflicts, and make other maintenance like reverting a commit less convenient... I'm closing as not-to-be-fixed. Please re-open if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add subtest count in test utils convenience methods to help avoid typos and other unexpected changes
5 participants